package org.jactao.v_1_0_test;

import org.jactao.common.LReferConfig;
import org.jactao.common.LClientConfig;
import org.jactao.registry.LRedisRegistry;
import org.jactao.registry.LRegistry;
import org.jactao.boot.LClient;
import org.jactao.v_1_0_test.service.LoginService;
import org.jactao.v_1_0_test.service.UserService;
import org.jactao.v_1_0_test.service.dto.UserDto;

/**
 * Created by fanzetao on 2018/4/4.
 */
public class AppConsumer {

    public static void main(String[] args) {
        LRegistry registry = new LRedisRegistry(
                "127.0.0.1", 6379, "@gonghui@");
        registry.init();

        LClientConfig config = new LClientConfig();
        config.setRegistry(registry);

        LClient client = new LClient(config);

        LReferConfig referConfig1 = new LReferConfig();
        referConfig1.setInterfaceClass(UserService.class);

        LReferConfig referConfig2 = new LReferConfig();
        referConfig2.setInterfaceClass(LoginService.class);

        client.refer(referConfig1);
        client.refer(referConfig2);

        client.start();

        UserService userService = client.getService(UserService.class);
        UserDto userDto = userService.register(Thread.currentThread().getName(),
                "111111");
        System.out.println("user register success, user id = " + userDto.getId());

        LoginService loginService = client.getService(LoginService.class);
        loginService.login(userDto.getUserName(), userDto.getPassword());

        loginService.logout(userDto.getUserName());

    }
}
